﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Document.cs" company="Microsoft">
//   Microsoft
// </copyright>
// <summary>
//   Defines the Document type.
// </summary>
// Copyright (c) Microsoft Corporation. All rights reserved.
// 
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES 
// OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
// ----------------------------------------------------------------------------------
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
// --------------------------------------------------------------------------------------------------------------------

namespace MySemanticSearch.Model
{
    using System.Collections.Generic;
    using System.ComponentModel;

    /// <summary>
    /// Class for creating list documents
    /// </summary>
    public class Document : INotifyPropertyChanged
    {
        /// <summary>
        /// Private dictionary that returns the icons for the document list
        /// </summary>
        private static readonly IDictionary<string, string> Map = new Dictionary<string, string>()
        {
            { "docx", "images/docx.png" },
            { "doc", "images/docx.png" },
            { "pdf", "images/pdf.png" }
        };

        /// <summary>
        /// Document path.
        /// </summary>
        private string path;

        /// <summary>
        /// Document extension.
        /// </summary>
        private string extension;

        /// <summary>
        /// Dcoument's associated score
        /// </summary>
        private double score = 0;

        /// <summary>
        /// PropertyChanged handler
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Gets or sets Score.
        /// </summary>
        public double Score
        {
            get
            {
                return this.score;
            }

            set
            {
                this.score = value;
                this.NotifyPropertyChanged("Score");
            }
        }
        
        /// <summary>
        /// Gets the Extension.
        /// </summary>
        public string Extension
        {
            get
            {
                return this.extension;
            }

            private set
            {
                if (value == this.extension)
                {
                    return;
                }

                this.extension = value;
                this.NotifyPropertyChanged("Extension");
            }
        }
        
        /// <summary>
        /// Gets or sets Path.
        /// </summary>
        public string Path
        {
            get
            {
                return this.path;
            }

            set
            {
                if (value == this.path)
                {
                    return;
                }

                this.path = value;
                this.Extension = System.IO.Path.GetExtension(value).Replace(".", string.Empty);
                this.NotifyPropertyChanged("Extension");
                this.NotifyPropertyChanged("FileType");
                this.NotifyPropertyChanged("Path");
                this.NotifyPropertyChanged("FileName");
            }
        }

        /// <summary>
        /// Gets FileName.
        /// </summary>
        public string FileName
        {
            get { return this.Path.Replace(System.IO.Path.GetExtension(this.Path), string.Empty); }
        }

        /// <summary>
        /// Gets FileType.
        /// </summary>
        public string FileType
        {
            get
            {
                return Map.ContainsKey(this.Extension) ? Map[this.Extension] : "images/empty.png";
            }
        }

        /// <summary>
        /// NotifyPropertyChanged method, used to notify when a property changes
        /// </summary>
        /// <param name="info">
        /// The info param.
        /// </param>
        private void NotifyPropertyChanged(string info)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
    }
}
